package com.itfreer.gis.map.style.transfer;

import java.util.LinkedHashMap;
import java.util.Map;

class MbSupermpLayer {
    /**
     * 获取wms图层的source对象
     */
    static Map<String, Object> WMS(Map<String, Object> source) {
        int tileSize = source.get("tileSize") == null ? 256 : (int)source.get("tileSize");
        int maxzoom = source.get("maxzoom") == null ? 22 : (int)source.get("maxzoom");
        int minzoom = source.get("minzoom") == null ? 0 : (int)source.get("minzoom");
        String scheme = source.get("scheme") == null ? "xyz" : (String)source.get("scheme");
        boolean urlComlete = source.get("urlComlete") == null ? false : (boolean)source.get("urlComlete");
        String layerName = source.get("layerName") == null ? "" : source.get("layerName").toString();
        String url = source.get("url").toString();
        url = urlComlete ? url : url + "?" // Supermap WMS地图服务地址
                + "version=1.1.1" //1.1.1、1.3.0
                + "&request=GetMap" // 调用的方法名称，获取地图必须是这个方法
                + "&layers=" + layerName // 要显示的图层名称
                + "&styles=" // 图层显示样式，同样多个样式名称间用，隔开；
                + "&srs=EPSG:3857"  // srs=EPSG:3857 也可以 如果版本号是1.3.0 则用crs。
                + "&bbox={bbox-epsg-3857}" // 使用map加载的wms的时候，使用这个标识来同步要获取地图的范围的坐标，必须为这个值
                + "&width=" + tileSize // 返回的图片的大小
                + "&height=" + tileSize // 返回的图片的大小
                + "&format=image/png" // 返回的图片格式
                + "&TRANSPARENT=TRUE"; // 设置背景是不是可以透明，没有数据的地方就进行透明
        LinkedHashMap<String, Object> mbSource = new LinkedHashMap<>();
        mbSource.put("type", "raster");
        mbSource.put("tileSize", tileSize);
        mbSource.put("tiles", new String[] { url });
        mbSource.put("maxzoom", maxzoom);
        mbSource.put("minzoom", minzoom);
        mbSource.put("scheme", scheme);
        return mbSource;
    }

    /**
     * 获取WMTS图层的source组装对象
     */
    static Map<String, Object> WMTS(Map<String, Object> source) {
        int tileSize = source.get("tileSize") == null ? 256 : (int)source.get("tileSize");
        int maxzoom = source.get("maxzoom") == null ? 22 : (int)source.get("maxzoom");
        int minzoom = source.get("minzoom") == null ? 0 : (int)source.get("minzoom");
        String scheme = source.get("scheme") == null ? "xyz" : (String)source.get("scheme");
        boolean urlComlete = source.get("urlComlete") == null ? false : (boolean)source.get("urlComlete");
        String layerName = source.get("layerName") == null ? "" : source.get("layerName").toString();
        String url = source.get("url").toString();
        url = urlComlete ? url : url + "?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&LAYER=" + layerName +
                "&STYLE=&TILEMATRIX={z}&TILEMATRIXSET=GoogleMapsCompatible_" + layerName + "&FORMAT=image/png&TILECOL={x}&TILEROW={y}";
        LinkedHashMap<String, Object> mbSource = new LinkedHashMap<>();
        mbSource.put("type", "raster");
        mbSource.put("tileSize", tileSize);
        mbSource.put("tiles", new String[] { url });
        mbSource.put("maxzoom", maxzoom);
        mbSource.put("minzoom", minzoom);
        mbSource.put("scheme", scheme);
        return mbSource;
    }

    /**
     * 获取TMS图层
     */
    static Map<String, Object> TMS(Map<String, Object> source) {
        boolean urlComlete = source.get("urlComlete") == null ? false : (boolean)source.get("urlComlete");
        String url = source.get("url").toString();
        url = urlComlete ? url : url + "/tiles/{z}/{x}/{y}.mvt";
        int maxzoom = source.get("maxzoom") == null ? 22 : (int)source.get("maxzoom");
        int minzoom = source.get("minzoom") == null ? 0 : (int)source.get("minzoom");
        String scheme = source.get("scheme") == null ? "tms" : (String)source.get("scheme");

        LinkedHashMap<String, Object> mbSource = new LinkedHashMap<>();
        mbSource.put("type", "vector");
        mbSource.put("tiles", new String[] { url });
        mbSource.put("maxzoom", maxzoom);
        mbSource.put("minzoom", minzoom);
        mbSource.put("scheme", scheme);
        return mbSource;
    }

    /**
     * 获取wfs图层
     */
    static Map<String, Object> WFS(Map<String, Object> source) {
        return null;
    }
}
